package com.xingda.packing.dmss.task.listener;

import com.xingda.packing.dmss.domain.PackProductionLine;
import com.xingda.packing.dmss.domain.ShuntProductionLine;
import com.xingda.packing.dmss.enums.TaskState;
import com.xingda.packing.dmss.enums.TaskType;
import com.xingda.packing.dmss.task.ticket.ScanCodeTicket;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
@Slf4j
public class ScanCodeListener implements TaskListenerService {

    @Resource
    ShuntProductionLine shuntProductionLine;

    @Override
    public boolean accept(PackProductionLine productionLine, int area) {
        return checkTask(productionLine.getRobot().getTaskTicket(area), TaskType.SCANCODE);
    }

    @Override
    public void monitor(PackProductionLine productionLine, int area) {
        if (productionLine.getRobot().isGrabComplete(area)) {
            ScanCodeTicket ticket = (ScanCodeTicket) productionLine.getRobot().getTaskTicket(area);
            shuntProductionLine.getShuntArea().takeWheelToSql(area);
            ticket.setState(TaskState.FINISH);
            productionLine.getRobot().resetStatus(area);
            productionLine.getRobot().listenerScanCodeEvent(ticket, area);
        }
    }
}
